<template>
    <div class="whole_container">
        <ul class="whole_container_list">
            <li v-for="(item,index) in list" :key="index" class="list_box animated rotateInUpRight">
                <div class="list_box_header">
                    <span class="label">{{item.type_name}}</span>
                    <span class="more" @click="goarticel(item,index)">更多 ></span>
                </div>
                <div class="list_box_img">
                    <img v-if="item.article_type_info.length == 0" src="../../../assets/img/nocontent.png" alt="" >
                    <img v-else :src="item.article_type_info[0].head_pic" alt="" @click="goarticel(item,index)">
                </div>
                <div class="list_box_article">
                    <ul class="list_box_article_list">
                        <li v-for="(tag,index) in item.article_type_info" :key="index" :class="{'actived':ind === index}" @click="goarticelDetail(item,tag)">
                            <div>
                                <span class="intro">{{tag.title}}</span>
                                <span class="date">{{tag.created_time}}</span>
                                <div style="clear:both;"></div>
                            </div>
                        </li>
                    </ul>
                </div>
            </li>
            <div style="clear:both;"></div>
        </ul>
    </div>
</template>
<script>
import axios from 'axios'
import { getAllarticle } from "@/api/business"
export default {
    metaInfo: {
        title: "生意经",
        meta: [
            {
                name: "keywords",
                content: "办公,租赁,房源,办公空间,房屋出租,办公空间出租,生意经,找办公空间,财税文章,找房Tips,找房,楼市趋势,全部"
            },
            {
                name: "description",
                content: "房大办公生意经"
            }
        ]
    },
    name:'Whole',
    data() {
        return {
            list:[],
            ind:0,
            typeid:this.$route.query.typeid,
        }
    },
    created(){
        this.$root.goIndex=2
    },
    methods:{
        fetchAllarticle(){
            getAllarticle().then((res)=>{
                if(res.data.code ==0){
                    this.list = res.data.data.reverse();
                }else{
                    this.$message.error(res.data.msg)
                }
            })
            .catch((error)=>{
                // this.$message.error('查询全部文章失败！请稍后重试！')
            })
        },
        goarticelDetail(item,tag){  // 从全部跳转到文章详情
            let typeid = item.type_id;
            let articelid = tag.article_id;
            switch(typeid){
                case 1 :
                    this.$router.push({path:'/home/business/officespace/spacedetail/'+ typeid + '/' + articelid});
                    break;
                case 2 :
                    this.$router.push({path:'/home/business/tips/tipsdetail/'+ typeid + '/' + articelid});
                    break;
                case 3 :
                    this.$router.push({path:'/home/business/lawworks/lawworksdetail/'+ typeid + '/' + articelid});
                    break;
                case 4 :
                    this.$router.push({path:'/home/business/financing/financingdetail/'+ typeid + '/' + articelid});
                    break;
                case 5 :
                    this.$router.push({path:'/home/business/preferential/preferendetail/'+ typeid + '/' + articelid});
                    break;
                case 6 :
                    this.$router.push({path:'/home/business/activity/activitydetail/'+ typeid + '/' + articelid});
                    break;
                case 7 :
                    this.$router.push({path:'/home/business/taxation/taxationdetail/'+ typeid + '/' + articelid});
                    break;
            }
        },

        goarticel(item,index){  // 从全部跳转到文章列表
            let typeid = item.type_id;
            let typeindex = index;
            switch(typeindex){
                case 0 :
                    this.$router.push({path:'/home/business/officespace/?typeid=' + typeid});
                    break;
                case 1 :
                    this.$router.push({path:'/home/business/tips/?typeid=' + typeid});
                    break;
                case 2 :
                    this.$router.push({path:'/home/business/LawWorks/?typeid=' + typeid});
                    break;
                case 3 :
                    this.$router.push({path:'/home/business/financing/?typeid=' + typeid});
                    break;
                case 4 :
                    this.$router.push({path:'/home/business/preferential/?typeid=' + typeid});
                    break;
                case 5 :
                    this.$router.push({path:'/home/business/activity/?typeid=' + typeid});
                    break;
                case 6 :
                    this.$router.push({path:'/home/business/taxation/?typeid=' + typeid});
                    break;
            }
        },
    },
     beforeRouteLeave(to, from, next) {
         // 设置下一个路由的 meta
        to.meta.keepAlive = true;  // 让 A 缓存，即不刷新
        next();
    },
    mounted() {
        this.fetchAllarticle();
    },
}
</script>
<style lang="scss" scoped>
@import "../../../style/common.scss";
@import "./whole.scss";
</style>
